package com.hpu.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hpu.entity.User;
import com.hpu.service.UserService;
import com.hpu.util.DateUtil;

public class SaveUserServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String id = request.getParameter("userid");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String sex = request.getParameter("sex");
		int age = Integer.parseInt(request.getParameter("age"));
		String role = request.getParameter("role");
		String employtime = DateUtil.getTimeYMD();
		
		UserService userService = new UserService();
		User user = new User();
		user.setId(id);
		user.setUsername(username);
		user.setPassword(password);
		user.setSex(sex);
		user.setAge(age);
		user.setRole(role);
		user.setEmploytime(employtime);
		userService.saveUser(user);
		
		request.getRequestDispatcher("/WEB-INF/views/adduser.jsp").forward(request, response);
	}

}
